package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.mapper.UserMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Service;

import org.springframework.transaction.annotation.Transactional;
import java.util.Set;


@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public UserVO findUserByUserName(String username) {
        //根据传进来的用户名查询用户信息
        UserVO userVO = baseMapper.findUserVoByUserName(username);
        //查询角色信息
        Set<RoleVO> roleVOSet = baseMapper.findRoleByUserId(userVO.getId());

        for (RoleVO roleVO : roleVOSet) {
            //查询权限信息 根据角色id
            Set<Permission> permissions = baseMapper.findPermissionByRoleVoID(roleVO.getId());
            roleVO.setPermission(permissions);
        }

        //封装到返回对象
        userVO.setRoles(roleVOSet);

        return userVO;
    }
}
